<include file="../Public/_header.html" />
<dl style="margin:10px 10px 5px; height:22px" class="clear">
	<dt class="left alR " style="width:43px;">上级：</dt>
  	<dd class="left alL"><input type="hidden" id="pid" value="{$pid}">
  		{:getCategoryNameById($pid,'无上级，为根！')}</dd>
  <br><br>
  <dt class="left alR " style="width:43px;">名称：</dt>
  	<dd class="left alL"><input type="text" id="desc" value="{$dict['desc']}">&nbsp;填汉字</dd>
  <br><br>
	<dt class="left alR " style="width:43px;">类别：</dt>
		<dd class="left alL"><input type="text" id="code" value="{$dict['code']}">&nbsp;填英文</dd>
	<br><br>
	<dt class="left alR " style="width:43px;">排序：</dt>
		<dd class="left alL"><input type="text" id="order" value="<php>echo empty($dict['order'])?'1':$dict['order'];</php>">&nbsp;填数字</dd>
	</dl>

<div class="clear"></div>
<br>
<div style="background:#F8F8F8; border-top:1px solid #E6E6E6; padding:5px;" class="alR">
  <php>if (isset($dict)) {</php>
  <input type="button" class="btn_b" onclick="_edit()" value="提交" />
  <php>}else {</php>
  <input type="button" class="btn_b" onclick="_add()" value="提交" />
  <php>}</php>
  <input type="button" class="btn_w" onclick="_cancel()" value="取消" />
</div>
<div id="showerror"></div>
<script type="text/javascript">

//添加地区
function _add() {
	var desc = $('#desc').val();
	if(desc=='') {
		ui.error('请输入名称');
		return ;
	}
	
	var code = $('#code').val();
	if(code=='') {
		ui.error('请输入类别');
		return ;
	}
	var order   = $('#order').val();
	var pid   = $('#pid').val();

	$.ajax({
 			type: "POST",
 			url: "{:U('/Dict/doAddCategory')}",
 			data:   {pid:pid,desc:desc,code:code,order:order},
 			success: function(msg){
 										$('#showerror').html(msg);
 										var obj	=	eval('(' + msg + ')');
								    if(obj.status==1){
												var url = "{:U('/Dict/index',array('parentId'=>$pid))}";
												k_success(obj.msg);
												k_page_redirect(url);
										}else{
												alert(obj.msg);
										}
 								}
		});
}

//编辑地区
function _edit() {
		var desc = $('#desc').val();
	if(desc=='') {
		ui.error('请输入名称');
		return ;
	}
	
	var code = $('#code').val();
	if(code=='') {
		ui.error('请输入类别');
		return ;
	}
	var order   = $('#order').val();
	var pid   = $('#pid').val();
	var id   = '{$dict['id']}';
	$.ajax({
 			type: "POST",
 			url: "{:U('/Dict/doEditCategory')}",
 			data:   {id:id,pid:pid,desc:desc,code:code,order:order},
 			success: function(msg){
 										$('#showerror').html(msg);
 										var obj	=	eval('(' + msg + ')');
								    if(obj.status==1){
												var url = "{:U('/Dict/index',array('parentId'=>$pid))}";
												k_success(obj.msg);
												k_page_redirect(url);
										}else{
												alert(obj.msg);
										}
 								}
		});
}

function _cancel() {
	ui.box.close();
}
</script>
